From b905f69d0258ffeb666d925e4e8b28d62f9cef88 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=98yvind=20Kol=C3=A5s?= Date: Sat, 27 Aug 2005 19:47:20 +0000 Subject: [PATCH] babl_log upgade --- ChangeLog | 22 ++++++++++++++++++++++ babl/babl-component.c | 11 +++++------ babl/babl-conversion.c | 33 ++++++++++++--------------------- babl/babl-db.h | 18 +++++++++--------- babl/babl-fish.c | 16 +++++++--------- babl/babl-format.c | 22 ++++++++++------------ babl/babl-image.c | 8 +++----- babl/babl-internal.h | 28 ++++++++++++++++++++++++---- babl/babl-introspect.c | 11 +++++++++-- babl/babl-memory.c | 8 ++++---- babl/babl-model.c | 12 +++++------- babl/babl-pixel-format.c | 22 ++++++++++------------ babl/babl-type.c | 9 +++++---- babl/babl-util.c | 3 ++- babl/base/type-u8.c | 2 +- tests/babl_class_name.c | 3 ++- 16 files changed, 130 insertions(+), 98 deletions(-) diff --git a/ChangeLog b/ChangeLog index bb49a9f..e289389 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2005-08-27 Øyvind Kolås + + * babl/babl-component.c: (babl_component_new): + * babl/babl-conversion.c: (conversion_new), (babl_conversion_new), + (babl_conversion_process): + * babl/babl-db.h: + * babl/babl-fish.c: (babl_conversion_find), (babl_fish), + (babl_fish_reference_process), (babl_fish_process), (babl_process): + * babl/babl-image.c: (babl_image_from_linear), (babl_image): + * babl/babl-internal.h: + * babl/babl-introspect.c: (babl_introspect), (model_introspect): + * babl/babl-memory.c: (babl_malloc), (babl_strdup), (babl_realloc), + (babl_calloc): + * babl/babl-model.c: (babl_model_new): + * babl/babl-pixel-format.c: (format_new), (babl_format_new): + * babl/babl-type.c: (babl_type_new): + * babl/babl-util.c: (babl_add_ptr_to_list): + * babl/base/type-u8.c: + * tests/babl_class_name.c: (test): + + Made babl_log(...) print the file, line and function by itself. + 2005-08-27 Øyvind Kolås * docs/graphics/Makefile.am: s/INSCAPE/INKSCAPE/ diff --git a/babl/babl-component.c b/babl/babl-component.c index fd4cef9..3724d96 100644 --- a/babl/babl-component.c +++ b/babl/babl-component.c @@ -79,10 +79,10 @@ babl_component_new (const char *name, if (BABL_IS_BABL (arg)) { - Babl *babl = (Babl*)arg; - - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); +#ifdef BABL_LOG + Babl *babl = (Babl*) arg; + babl_log ("%s unexpected", babl_class_name (babl->class_type)); +#endif } /* if we didn't point to a babl, we assume arguments to be strings */ @@ -108,8 +108,7 @@ babl_component_new (const char *name, else { - babl_log ("%s(): unhandled parameter '%s' for format '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for format '%s'", arg, name); exit (-1); } } diff --git a/babl/babl-conversion.c b/babl/babl-conversion.c index 0b2961f..278dfc7 100644 --- a/babl/babl-conversion.c +++ b/babl/babl-conversion.c @@ -63,15 +63,13 @@ conversion_new (const char *name, } else if (planar_bit) { - babl_log ("%s(): planar_bit support not implemented yet", - __FUNCTION__); + babl_log ("planar_bit support not implemented yet"); } break; case BABL_MODEL: if (linear) { - babl_log ("%s(): linear support for model conversion not supported", - __FUNCTION__); + babl_log ("linear support for model conversion not supported"); } else if (planar) { @@ -81,8 +79,7 @@ conversion_new (const char *name, } else if (planar_bit) { - babl_log ("%s(): planar_bit support for model conversion not supported", - __FUNCTION__); + babl_log ("planar_bit support for model conversion not supported"); } break; case BABL_FORMAT: @@ -100,18 +97,16 @@ conversion_new (const char *name, } else if (planar_bit) { - babl_log ("%s(): planar_bit support for pixelformat conversion not supported", - __FUNCTION__); + babl_log ("planar_bit support for pixelformat conversion not supported"); } break; default: - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", babl_class_name (babl->class_type)); break; } if (!babl) { - babl_log ("%s(name='%s', ...): creation failed", __FUNCTION__, name); + babl_log ("args=(name='%s', ...): creation failed", name); return NULL; } @@ -164,8 +159,7 @@ babl_conversion_new (const char *name, { if (got_func++) { - babl_log ("%s(): already got a conversion func, registration of multiple might be possible later\n", - __FUNCTION__); + babl_log ("already got a conversion func, registration of multiple might be possible later\n"); } linear = va_arg (varg, BablFuncLinear); } @@ -174,8 +168,7 @@ babl_conversion_new (const char *name, { if (got_func++) { - babl_log ("%s(): already got a conversion func, registration of multiple might be possible later\n", - __FUNCTION__); + babl_log ("already got a conversion func, registration of multiple might be possible later\n"); } planar = va_arg (varg, BablFuncPlanar); } @@ -184,8 +177,7 @@ babl_conversion_new (const char *name, { if (got_func++) { - babl_log ("%s(): already got a conversion func, registration of multiple might be possible later\n", - __FUNCTION__); + babl_log ("already got a conversion func, registration of multiple might be possible later\n"); } planar_bit = va_arg (varg, BablFuncPlanarBit); } @@ -208,8 +200,7 @@ babl_conversion_new (const char *name, } else { - babl_log ("%s(): unhandled parameter '%s' for format '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for format '%s'", arg, name); exit (-1); } } @@ -332,8 +323,8 @@ babl_conversion_process (BablConversion *conversion, n); break; default: - babl_log ("%s(%s, %p, %p, %li) unhandled conversion type: %s", - __FUNCTION__, conversion->instance.name, source, destination, n, + babl_log ("args=(%s, %p, %p, %li) unhandled conversion type: %s", + conversion->instance.name, source, destination, n, babl_class_name (conversion->instance.class_type)); break; } diff --git a/babl/babl-db.h b/babl/babl-db.h index bd4f500..8dd0884 100644 --- a/babl/babl-db.h +++ b/babl/babl-db.h @@ -71,8 +71,7 @@ DB_DEF Babl * db_find (const char *name) if (db[0]) sample_type = babl_class_name (db[0]->class_type); - babl_log ("%s(\"%s\"): failed (query performed on a %s database)", - __FUNCTION__, name, sample_type); + babl_log ("failed (query performed on a %s database)", sample_type); } return ret; } @@ -118,13 +117,13 @@ db_insert (Babl *babl) if (collision) { - if (collision->instance.id == babl->instance.id) - babl_log ("%s: conflicting id: existing(%i:'%s') - new(%i:'%s')", - __FUNCTION__, collision->instance.id, collision->instance.name, + if (!strcmp (collision->instance.name, babl->instance.name)) + babl_log ("conflicting name: existing(%i:'%s') - new(%i:'%s')", + collision->instance.id, collision->instance.name, babl->instance.id, babl->instance.name); - else if (!strcmp (collision->instance.name, babl->instance.name)) - babl_log ("%s: conflicting name: existing(%i:'%s') - new(%i:'%s')", - __FUNCTION__, collision->instance.id, collision->instance.name, + else if (collision->instance.id == babl->instance.id) + babl_log ("conflicting id: existing(%i:'%s') - new(%i:'%s')", + collision->instance.id, collision->instance.name, babl->instance.id, babl->instance.name); return collision; } @@ -136,7 +135,8 @@ db_insert (Babl *babl) new_db = babl_realloc (db, (db_size + DB_INCREMENT_SIZE) * sizeof (BablInstance*)); if (!new_db) { - babl_log ("db_insert: unable to reallocate memory, element (%i:'%s') not inserted", babl->instance.id, babl->instance.name); + babl_log ("unable to reallocate memory, element (%i:'%s') not inserted", + babl->instance.id, babl->instance.name); return NULL; } db = new_db; diff --git a/babl/babl-fish.c b/babl/babl-fish.c index 9dff7b1..329e15f 100644 --- a/babl/babl-fish.c +++ b/babl/babl-fish.c @@ -108,7 +108,7 @@ BablConversion *babl_conversion_find (void *source, if (!data.result) { - babl_log ("%s('%s', '%s'): failed, aborting", __FUNCTION__, + babl_log ("args=('%s', '%s'): failed, aborting", data.source->instance.name, data.destination->instance.name); exit (-1); return NULL; @@ -170,8 +170,7 @@ babl_fish (void *source, if (!source_format) { - babl_log ("%s(%p, %p) source format invalid", - __FUNCTION__, source, destination); + babl_log ("args=(%p, %p) source format invalid", source, destination); } if (BABL_IS_BABL (destination)) @@ -186,8 +185,7 @@ babl_fish (void *source, if (!destination_format) { - babl_log ("%s(%p, %p) destination format invalid", - __FUNCTION__, source, destination); + babl_log ("args=(%p, %p) destination format invalid", source, destination); } return babl_fish_reference_new (source_format, destination_format); @@ -338,8 +336,8 @@ babl_fish_reference_process (Babl *babl, if (BABL_IS_BABL (source) || BABL_IS_BABL (destination)) { - babl_log ("%s(%p, %p, %p, %li): trying to handle BablImage (unconfirmed code)", - __FUNCTION__, babl_fish, source, destination, n); + babl_log ("args=(%p, %p, %p, %li): trying to handle BablImage (unconfirmed code)", + babl_fish, source, destination, n); } convert_to_double ( @@ -390,7 +388,7 @@ babl_fish_process (Babl *babl, void *destination, long n) { - babl_log ("%s(): NYI", __FUNCTION__); + babl_log ("NYI"); return -1; } @@ -434,7 +432,7 @@ babl_process (Babl *babl, return 0; } - babl_log ("%s(): eek", __FUNCTION__); + babl_log ("eek"); return -1; } diff --git a/babl/babl-format.c b/babl/babl-format.c index fe3406d..5511290 100644 --- a/babl/babl-format.c +++ b/babl/babl-format.c @@ -61,8 +61,7 @@ format_new (const char *name, if (component[j] == model->component[i]) goto component_found; } - babl_log ("%s(): matching source component for %s in model %s not found", - __FUNCTION__, + babl_log ("matching source component for %s in model %s not found", model->component[i]->instance.name, model->instance.name); exit (-1); component_found: @@ -150,8 +149,8 @@ babl_format_new (const char *name, case BABL_COMPONENT: if (!model) { - babl_log ("%s(): no model specified before component %s", - __FUNCTION__, babl->instance.name); + babl_log ("no model specified before component %s", + babl->instance.name); } component [components] = (BablComponent*) babl; type [components] = current_type; @@ -160,8 +159,8 @@ babl_format_new (const char *name, if (components>=BABL_MAX_COMPONENTS) { - babl_log ("%s(): maximum number of components (%i) exceeded for %s", - __FUNCTION__, BABL_MAX_COMPONENTS, name); + babl_log ("maximum number of components (%i) exceeded for %s", + BABL_MAX_COMPONENTS, name); } break; case BABL_SAMPLING: @@ -170,8 +169,8 @@ babl_format_new (const char *name, case BABL_MODEL: if (model) { - babl_log ("%s(%s): model %s already requested", - __FUNCTION__, babl->instance.name, model->instance.name); + babl_log ("args=(%s): model %s already requested", + babl->instance.name, model->instance.name); } model = (BablModel*)arg; break; @@ -186,8 +185,8 @@ babl_format_new (const char *name, case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", + babl_class_name (babl->class_type)); break; case BABL_SKY: /* shut up compiler */ break; @@ -211,8 +210,7 @@ babl_format_new (const char *name, else { - babl_log ("%s: unhandled parameter '%s' for format '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for format '%s'", arg, name); exit (-1); } } diff --git a/babl/babl-image.c b/babl/babl-image.c index 7e02aab..042b66e 100644 --- a/babl/babl-image.c +++ b/babl/babl-image.c @@ -135,7 +135,7 @@ babl_image_from_linear (void *buffer, } break; default: - babl_log ("%s(): Eeeek!", __FUNCTION__); + babl_log ("Eeeek!"); break; } @@ -182,8 +182,7 @@ babl_image (void *first, } else { - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", babl_class_name (babl->class_type)); return NULL; } } @@ -203,8 +202,7 @@ babl_image (void *first, if (components>=BABL_MAX_COMPONENTS) { - babl_log ("%s(): maximum number of components (%i) exceeded", - __FUNCTION__, BABL_MAX_COMPONENTS); + babl_log ("maximum number of components (%i) exceeded", BABL_MAX_COMPONENTS); } arg = va_arg (varg, char *); diff --git a/babl/babl-internal.h b/babl/babl-internal.h index 277b4b1..8879c82 100644 --- a/babl/babl-internal.h +++ b/babl/babl-internal.h @@ -30,15 +30,18 @@ #include "babl-util.h" #include "babl-memory.h" #include "babl-classes.h" + +/* internal classes */ #include "babl-conversion.h" +/* */ -#define babl_log(fmt, args...) do { \ - fprintf (stdout, "babl: "); \ - fprintf (stdout, fmt, args); \ +#define babl_log(args...) do { \ + fprintf (stdout, "%s:%i %s() ", \ + __FILE__, __LINE__, __FUNCTION__); \ + fprintf (stdout, args); \ fprintf (stdout, "\n"); \ } while (0) - extern int babl_hmpf_on_name_lookups; #define BABL_DEFINE_EACH(type_name) \ @@ -81,19 +84,36 @@ type_name (const char *name) \ return babl; \ } +#ifndef BABL_INIT_HOOK +#define BABL_INIT_HOOK +#endif +#ifndef BABL_PRE_INIT_HOOK +#define BABL_PRE_INIT_HOOK +#endif +#ifndef BABL_DESTROY_HOOK +#define BABL_DESTROY_HOOK +#endif +#ifndef BABL_DESTROY_PRE_HOOK +#define BABL_DESTROY_PRE_HOOK +#endif + #define BABL_DEFINE_INIT(type_name) \ void \ type_name##_init (void) \ { \ + BABL_PRE_INIT_HOOK; \ db_init (); \ + BABL_INIT_HOOK; \ } #define BABL_DEFINE_DESTROY(type_name) \ void \ type_name##_destroy (void) \ { \ + BABL_DESTROY_PRE_HOOK; \ db_each (each_##type_name##_destroy, NULL); \ db_destroy (); \ + BABL_DESTROY_HOOK; \ } #define BABL_CLASS_TEMPLATE(type_name) \ diff --git a/babl/babl-introspect.c b/babl/babl-introspect.c index 91a2a80..a933b28 100644 --- a/babl/babl-introspect.c +++ b/babl/babl-introspect.c @@ -20,16 +20,20 @@ #include "babl.h" #include "babl-internal.h" /* for babl_log */ +#ifdef BABL_LOG + static void sampling_introspect (Babl *babl); static void model_introspect (Babl *babl); static void type_introspect (Babl *babl); static void format_introspect (Babl *babl); static int each_introspect (Babl *babl, void *user_data); +#endif void babl_introspect (void) { +#ifdef BABL_LOG babl_log ("Introspection report%s",""); babl_log ("====================================================%s" ,""); @@ -56,8 +60,10 @@ babl_introspect (void) babl_fish_each (each_introspect, NULL); babl_log ("%s", ""); +#endif } +#ifdef BABL_LOG static int list_length (void **list) { void **ptr; @@ -112,8 +118,8 @@ model_introspect (Babl *babl) for (i=0; i< babl->model.components; i++) { - babl_log ("\t\tindex[%i] = '%s'", - i, BABL(babl->model.component[i])->instance.name ); + babl_log ("\t\tindex[%i] = '%s'", i, + BABL(babl->model.component[i])->instance.name ); } } @@ -187,3 +193,4 @@ each_introspect (Babl *babl, } return 0; } +#endif diff --git a/babl/babl-memory.c b/babl/babl-memory.c index 3a7c81b..ff2026f 100644 --- a/babl/babl-memory.c +++ b/babl/babl-memory.c @@ -60,7 +60,7 @@ babl_malloc (size_t size) assert (size); ret = malloc (size + OFFSET); if (!ret) - babl_log ("%s(%i): failed", __FUNCTION__, size); + babl_log ("args=(%i): failed", size); BAI(ret + OFFSET)->signature = signature; BAI(ret + OFFSET)->size = size; @@ -75,7 +75,7 @@ babl_strdup (const char *s) ret = babl_malloc (strlen (s)+1); if (!ret) - babl_log ("%s(%s): failed", __FUNCTION__, s); + babl_log ("args=(%s): failed", s); strcpy (ret, s); strdups++; @@ -123,7 +123,7 @@ babl_realloc (void *ptr, ret = realloc (BAI(ptr), size + OFFSET); if (!ret) - babl_log ("%s(%p, %i): failed", __FUNCTION__, ptr, size); + babl_log ("args=(%p, %i): failed", ptr, size); BAI(ret+OFFSET)->signature = signature; BAI(ret+OFFSET)->size = size; @@ -139,7 +139,7 @@ babl_calloc (size_t nmemb, void *ret = babl_malloc (nmemb*size); if (!ret) - babl_log ("%s(%i, %i): failed", __FUNCTION__, nmemb, size); + babl_log ("args=(%i, %i): failed", nmemb, size); memset (ret, 0, nmemb*size); diff --git a/babl/babl-model.c b/babl/babl-model.c index 76d0878..159e468 100644 --- a/babl/babl-model.c +++ b/babl/babl-model.c @@ -91,12 +91,12 @@ babl_model_new (const char *name, if (components>=BABL_MAX_COMPONENTS) { - babl_log ("%s(): maximum number of components (%i) exceeded for %s", - __FUNCTION__, BABL_MAX_COMPONENTS, name); + babl_log ("maximum number of components (%i) exceeded for %s", + BABL_MAX_COMPONENTS, name); } break; case BABL_MODEL: - babl_log ("%s(): submodels not handled yet", __FUNCTION__); + babl_log ("submodels not handled yet"); break; case BABL_TYPE: case BABL_SAMPLING: @@ -113,8 +113,7 @@ babl_model_new (const char *name, case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", babl_class_name (babl->class_type)); break; case BABL_SKY: /* shut up compiler */ break; @@ -128,8 +127,7 @@ babl_model_new (const char *name, else { - babl_log ("%s: unhandled parameter '%s' for babl_model '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for babl_model '%s'", arg, name); exit (-1); } } diff --git a/babl/babl-pixel-format.c b/babl/babl-pixel-format.c index fe3406d..5511290 100644 --- a/babl/babl-pixel-format.c +++ b/babl/babl-pixel-format.c @@ -61,8 +61,7 @@ format_new (const char *name, if (component[j] == model->component[i]) goto component_found; } - babl_log ("%s(): matching source component for %s in model %s not found", - __FUNCTION__, + babl_log ("matching source component for %s in model %s not found", model->component[i]->instance.name, model->instance.name); exit (-1); component_found: @@ -150,8 +149,8 @@ babl_format_new (const char *name, case BABL_COMPONENT: if (!model) { - babl_log ("%s(): no model specified before component %s", - __FUNCTION__, babl->instance.name); + babl_log ("no model specified before component %s", + babl->instance.name); } component [components] = (BablComponent*) babl; type [components] = current_type; @@ -160,8 +159,8 @@ babl_format_new (const char *name, if (components>=BABL_MAX_COMPONENTS) { - babl_log ("%s(): maximum number of components (%i) exceeded for %s", - __FUNCTION__, BABL_MAX_COMPONENTS, name); + babl_log ("maximum number of components (%i) exceeded for %s", + BABL_MAX_COMPONENTS, name); } break; case BABL_SAMPLING: @@ -170,8 +169,8 @@ babl_format_new (const char *name, case BABL_MODEL: if (model) { - babl_log ("%s(%s): model %s already requested", - __FUNCTION__, babl->instance.name, model->instance.name); + babl_log ("args=(%s): model %s already requested", + babl->instance.name, model->instance.name); } model = (BablModel*)arg; break; @@ -186,8 +185,8 @@ babl_format_new (const char *name, case BABL_FISH: case BABL_FISH_REFERENCE: case BABL_IMAGE: - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", + babl_class_name (babl->class_type)); break; case BABL_SKY: /* shut up compiler */ break; @@ -211,8 +210,7 @@ babl_format_new (const char *name, else { - babl_log ("%s: unhandled parameter '%s' for format '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for format '%s'", arg, name); exit (-1); } } diff --git a/babl/babl-type.c b/babl/babl-type.c index c11d4c4..6812231 100644 --- a/babl/babl-type.c +++ b/babl/babl-type.c @@ -84,10 +84,11 @@ babl_type_new (const char *name, if (BABL_IS_BABL (arg)) { +#ifdef BABL_LOG Babl *babl = (Babl*)arg; - babl_log ("%s(): %s unexpected", - __FUNCTION__, babl_class_name (babl->class_type)); + babl_log ("%s unexpected", babl_class_name (babl->class_type)); +#endif } /* if we didn't point to a babl, we assume arguments to be strings */ else if (!strcmp (arg, "id")) @@ -124,8 +125,8 @@ babl_type_new (const char *name, else { - babl_log ("%s(): unhandled parameter '%s' for format '%s'", - __FUNCTION__, arg, name); + babl_log ("unhandled parameter '%s' for format '%s'", + arg, name); exit (-1); } } diff --git a/babl/babl-util.c b/babl/babl-util.c index 14ceba1..3d40fe8 100644 --- a/babl/babl-util.c +++ b/babl/babl-util.c @@ -21,6 +21,7 @@ #include #include #include "babl-memory.h" +#include "babl-internal.h" static int list_length (void **list) { @@ -52,7 +53,7 @@ babl_add_ptr_to_list (void ***list, if (!(*list)) { - fprintf (stderr, "%s(): eeek! failed to realloc", __FUNCTION__); + babl_log ("failed to realloc"); } (*list)[orig_len]=new; diff --git a/babl/base/type-u8.c b/babl/base/type-u8.c index 59eb4df..a979021 100644 --- a/babl/base/type-u8.c +++ b/babl/base/type-u8.c @@ -103,7 +103,7 @@ convert_double_##name (void *src, \ src, dst, src_pitch, dst_pitch, n); \ } -MAKE_CONVERSIONS (u8, 0.0, 1.0, 0x00, 0xff); +MAKE_CONVERSIONS (u8, 0.0, (255.0F/256.0F)*1.0, 0x00, 0xff); MAKE_CONVERSIONS (u8_luma, 0.0, 1.0, 16, 235); MAKE_CONVERSIONS (u8_chroma, 0.0, 1.0, 16, 240); diff --git a/tests/babl_class_name.c b/tests/babl_class_name.c index d411518..c011150 100644 --- a/tests/babl_class_name.c +++ b/tests/babl_class_name.c @@ -20,6 +20,7 @@ #include #include #include "babl.h" +#include "babl-internal.h" struct { @@ -56,7 +57,7 @@ test (void) if (strcmp (reference[i].name, babl_class_name (reference[i].klass))) { OK=0; - printf ("'%s'!='%s'\n", reference[i].name, babl_class_name (reference[i].klass)); + babl_log ("'%s'!='%s'\n", reference[i].name, babl_class_name (reference[i].klass)); } i++; } -- 2.30.2